from rest_framework import serializers

from apps.goods.models import SKU
from apps.orders.models import OrderInfo, OrderGoods

class SKUSimpleSerializer(serializers.ModelSerializer):
    class Meta:
        model = SKU
        fields = [
            'name',
            'default_image'
        ]

class OrderGoodsModelSerializer(serializers.ModelSerializer):
    # 当前订单商品对象关联的"单一的"SKU对象
    sku = SKUSimpleSerializer()

    class Meta:
        model = OrderGoods
        fields = [
            'count',
            'price',
            'sku'
        ]

class OrderDetialSerializers(serializers.ModelSerializer):
    user = serializers.StringRelatedField()
    skus = OrderGoodsModelSerializer(many=True)
    class Meta:
        model = OrderInfo
        fields = "__all__"



class OrderListSerializers(serializers.ModelSerializer):
    class Meta:
        model = OrderInfo
        fields = ["order_id", "create_time"]
